package com.sxt.consumer;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 雷哥
 * @Date: 2020/10/07/23:32
 * @Description:
 */
@Component
public class RoutingTopicConsumer {

  @RabbitListener(bindings =@QueueBinding(   //把队列和交换机进行绑定
      value = @Queue("topicQueue1"),  //绑定队列
      key = {"user.*"},
      exchange = @Exchange(name = "topics",type = ExchangeTypes.TOPIC )//绑定交换机和设置交换机的名称和类型
  )
  )
  public void receive1(String message){
    System.out.println("消费者user.*接收到消息:"+message);
  }

  @RabbitListener(bindings =@QueueBinding(
      value = @Queue("topicQueue2"),
      key = {"user.#"},
      exchange = @Exchange(name = "topics",type = ExchangeTypes.TOPIC )
  )
  )
  public void receive2(String message){
    System.err.println("消费者user.#接收到消息:"+message);
  }

}
